{extend name="public/base" /}
{block name="title"}分配权限{/block}
{block name="css"}{/block}
{block name="main"}

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h5>分配权限 <span class="badge badge-danger badge-bg">{$group_data['title']}</span></h5>
                <div class="ibox-tools">
                    <a class="collapse-link">
                        <i class="fa fa-chevron-up"></i>
                    </a>
                    <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                        <i class="fa fa-wrench"></i>
                    </a>
                    <ul class="dropdown-menu dropdown-user">
                        {volist name="groups" id="vo"}
                        <li><a href="{:url('Rule/ruleGroup',['id'=>$vo['id']])}">{$vo.title}</a></li>
                        {/volist}
                    </ul>
                    <a class="close-link">
                        <i class="fa fa-times"></i>
                    </a>
                </div>
            </div>
            <div class="ibox-content" style="padding:10px">
                <h1>为<span class="text-danger">{$group_data['title']}</span>分配权限</h1>
                <form action="" class="ajax-form" method="post">
                    <input type="hidden" name="id" value="{$group_data['id']}">
                    <table class="table table-striped table-bordered table-hover table-condensed ">
                        {foreach name="rule_data" item="v"}
                        {empty name="v['_data']"}
                        <tr class="b-group">
                            <th width="10%">
                                <label>
                                    {$v['title']}
                                    <input type="checkbox" name="rule_ids[]" value="{$v['id']}" {if condition="in_array($v['id'],$group_data['rules'])"}  checked="checked"{/if} onclick="checkAll(this)" >
                                </label>
                            </th>
                            <td></td>
                        </tr>
                        {else /}
                        <tr class="b-group">
                            <th width="10%">
                                <label>
                                    {$v['title']} <input type="checkbox" name="rule_ids[]" value="{$v['id']}" {if condition="in_array($v['id'],$group_data['rules'])"}  checked="checked"{/if} onclick="checkAll(this)">
                                </label>
                            </th>
                            <td class="b-child">
                                {foreach name="v['_data']" item="n"}
                                <table class="table table-striped table-bordered table-hover table-condensed">
                                    <tr class="b-group">
                                        <th width="10%">
                                            <label>
                                                {$n['title']} <input type="checkbox" name="rule_ids[]" value="{$n['id']}" {if condition="in_array($n['id'],$group_data['rules'])"}  checked="checked"{/if} onclick="checkAll(this)">
                                            </label>
                                        </th>
                                        <td>
                                            {notempty name="n['_data']"}
                                            {volist name="n['_data']" id="c"}
                                            <label>
                                                &emsp;{$c['title']} <input type="checkbox" name="rule_ids[]" value="{$c['id']}" {if condition="in_array($c['id'],$group_data['rules'])"}  checked="checked"{/if} >
                                            </label>
                                            {/volist}
                                            {/notempty}
                                        </td>
                                    </tr>
                                </table>
                                {/foreach}
                            </td>
                        </tr>
                        {/empty}
                        {/foreach}
                        <tr>
                            <th></th>
                            <td>
                                <input class="btn btn-success" type="submit" value="提交">
                            </td>
                        </tr>
                    </table>
                </form>
            </div>
        </div>
    </div>
</div>
{/block}
{block name="js"}
<script>
function checkAll(obj){
  $(obj).parents('.b-group').eq(0).find("input[type='checkbox']").prop('checked', $(obj).prop('checked'));
}
//选中复选框,父级复选框跟着选中
$('input[type="checkbox"]').click(function(e){
  var $group = $(this).parents('.b-group');
  if ($(this).prop('checked')) {
    $.each($group,function(i,v){
      $(v).find('input[type="checkbox"]:eq(0)').prop('checked','checked');
    })
  }

})
</script>
{/block}